package com.example.controller;

import com.example.domain.Student;
import com.example.domain.Teacher;
import com.example.domain.User;
import com.example.service.StudentService;
import com.example.service.TeacherService;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/system")
public class SystemController {
    
    @Autowired
    UserService userService;
    @Autowired
    StudentService studentService;
    @Autowired
    TeacherService teacherService;
    
    @RequestMapping(value = "/allAcounts", method = RequestMethod.POST)
    public List<String> getAllAccounts() {
        List<String> accounts = new ArrayList<>();
        final List<String> userCollect =
                userService.getAllUser().stream().map(User::getAccount).collect(Collectors.toList());
        
        final List<String> studentCollect =
                studentService.getAllStudents().stream().map(Student::getAccount).collect(Collectors.toList());
        
        final List<String> teacherCollect =
                teacherService.getAllTeachers().stream().map(Teacher::getAccount).collect(Collectors.toList());
        
        accounts.addAll(userCollect);
        accounts.addAll(teacherCollect);
        accounts.addAll(studentCollect);
        
        return accounts;
    }
}
